<?php if (!defined('THINK_PATH')) exit(); echo W('Header');?>
<script type="text/javascript">
    function deleteCartGoods(rec_id) {
        Ajax.call('delete_cart_goods.php', 'id=' + rec_id, deleteCartGoodsResponse, 'POST', 'JSON');
    }
    /**
     * 接收返回的信息
     */
    function deleteCartGoodsResponse(res) {
        if (res.error) {
            alert(res.err_msg);
        }
        else {
            $("#ECS_CARTINFO").html(res.content);
        }
    }
    $(function () {
        $("#ECS_CARTINFO li.shopWhite").mouseenter(function () {
            $(this).removeClass("shopWhite");
            $(this).addClass("shopGray");
        });
        $("#ECS_CARTINFO li.shopWhite").mouseleave(function () {
            $(this).removeClass("shopGray");
            $(this).addClass("shopWhite");
        });
    })
</script>
<div class="blank"></div>
<div class="block_s">
    <div id="J_FilterBar" class="cart-filter-bar">
        <ul id="J_CartSwitch" class="switch-cart">
            <li class="btn-switch-cart switch-cart-0 current"><a href="#" class="J_MakePoint"><em>全部商品</em><span
                    class="number"></span><span class="pipe"></span></a></li>
        </ul>
        <div class="cart-sum" style="display:none"></div>
        <div class="wrap-line">
            <div class="floater" style="width: 123px; left: -1px; "></div>
        </div>
    </div>
    <script type="text/javascript" src="js/showdiv.js"></script>
    <script type="text/javascript">
        var user_name_empty = "请输入您的用户名！";
        var email_address_empty = "请输入您的电子邮件地址！";
        var email_address_error = "您输入的电子邮件地址格式不正确！";
        var mobile_address_empty = "请输入您的手机号！";
        var mobile_address_error = "您输入的手机号格式不正确！";
        var new_password_empty = "请输入您的新密码！";
        var confirm_password_empty = "请输入您的确认密码！";
        var both_password_error = "您两次输入的密码不一致！";
        var show_div_text = "请点击更新购物车按钮";
        var show_div_exit = "关闭";
    </script>
    <Div class="nstep_products ">
        <div class="flowBox">
            <?php if($cartArr): ?><form id="formCart" name="formCart" method="post" action="flow.php">
                    <table style="text-align:center">
                        <th class="select-all J_SelectAll" bgcolor="#ffffff" style="text-align:left; margin-left:5px;"></th>
                        <th bgcolor="#ffffff"  style="width:40%;">商品名称</th>
                        <th bgcolor="#ffffff" style="text-align: center;width:15%;" >单价(元)</th>
                        <th bgcolor="#ffffff" style="text-align: center;width:15%" >数量</th>
                        <th bgcolor="#ffffff" style="text-align: center;width:15%" >金额(元)</th>
                        <th bgcolor="#ffffff" style="width:15%" >操作</th>
                    </table>
                    <table width="100%" style="border:#ccc solid 1px;text-align:center">
                        <?php if(is_array($cartArr)): foreach($cartArr as $key=>$v): ?><tr id="tr_goods_<?php echo ($v["goods_id"]); ?>" class="cartList" style="border:#f00 solid 1px;">
                                <td style="width:5%">
                                    <input type="checkbox" name="box" value="<?php echo ($v["goods_id"]); ?>" onclick = "jisuan(this)"/>
                                </td>
                                <td bgcolor="#ffffff" class="nstep_pbox" style="width:35%">
                                    <p class="f_l"><a href="<?php echo U(GROUP_NAME.'/Goods/index',array('id'=>$v['goods_id']));?>"
                                                      target="_blank"><img src="<?php echo U('/'.$v['goods']['img']);?>" border="0"
                                                                           title="<?php echo ($goods['name']); ?>" width="80" height="80"/></a>
                                    </p>
                                    <p class="nstep_name">
                                        <a href="<?php echo U(GROUP_NAME.'/Goods/index',array('id'=>$v['goods_id']));?>"
                                           target="_blank" class="f6"><?php echo ($v['goods']['name']); ?></a>
                                    </p>
                                </td>
                                <td bgcolor="#ffffff" style="width:15%">
                                    <p class="price-line" >
                                        <em class="price-original" style="text-align: center">￥<?php echo ($v['goods']['market_price']); ?>元</em>
                                    </p>
                                    <p class="price-line">
                                        <em class="price-now" style="text-align: center">￥<?php echo ($v['goods']['shop_price']); ?>元</em>
                                    </p>
                                </td>
                                <td bgcolor="#ffffff" style="width:15%">
                                    <div class="item-amount">
                                        <a  href="javascript:void(0)"
                                           onclick="changenum(<?php echo ($v["goods_id"]); ?>,1,<?php echo ($v['goods']['shop_price']); ?>)" class="add">+</a>
                                        <input type="text" name="goods_number[<?php echo ($v["goods_id"]); ?>]" id="goods_number_<?php echo ($v["goods_id"]); ?>"
                                               value="<?php echo ($v["num"]); ?>" size="1" class="shuliang" style="text-align:center "  
                                               onchange="change_goods_number(<?php echo ($v["goods_id"]); ?>,this.value,<?php echo ($v['goods']['shop_price']); ?>)"/>
                                        <a href="javascript:void(0)"
                                           onclick="changenum(<?php echo ($v["goods_id"]); ?>,-1,<?php echo ($v['goods']['shop_price']); ?>)" class="sub">-</a>
                                    </div>
                                </td>
                                <td style="width:15%" bgcolor="#ffffff" id="goods_subtotal_<?php echo ($v["goods_id"]); ?>" class="chkprice ">
                                    ￥<em name="price_<?php echo ($v["goods_id"]); ?>"><?php echo ($v['goods']['market_price']*$v["num"]); ?></em>元
                                </td>
                                <td style="width:15%" bgcolor="#ffffff"><a
                                        href="javascript:void(0);" onclick="if(confirm('确定删除?')==true)return remove(<?php echo ($v["goods_id"]); ?>);"
                                        style=" display:block; text-align:center">删除</a>
                                </td>
                            </tr><?php endforeach; endif; ?>
                    </table>
                    <table width="100%">
                        <tr>
                            <td bgcolor="#ffffff" id="total_desc" class="nstep1_count">
                                <div class="float-bar-wrapper">
                                    <div class="btn-area">
                                        <a class="submit-btns" style="float:right;margin-left:10px;"
                                                             onclick="checkout()">结算</a>
                                        <a class="submit-btns" style="float:right;margin-left:10px;"
                                           onClick="javascript :history.back(-1);">继续购物</a>
                                    </div>
                                    <div class="price-sum">
                                        购物金额小计￥ <em name="total">0</em>元
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </table>
                    <!-- <input type="hidden" name="step" value="update_cart" />-->
                </form>

                <?php else: ?>
                <div style="text-align:center"><a href="<?php echo U(GROUP_NAME.'/Index');?>"> <span style="font-weight: bolder;font-size: 20px;color: #000;">空空如也,点击购物</span></a><div><a href="<?php echo U(GROUP_NAME.'/Index');?>"><img src="__PUBLIC__/Images/cart.jpg" alt="空购物车" ></a></div></div><?php endif; ?>
            <script type="text/javascript">
                function changenum(rec_id, diff, price) {
                    var goods_number = Number($('#goods_number_' + rec_id).val()) + Number(diff);
                    if (goods_number < 1) {
                        alert("购买数量不能少于1件");
                    }
                    else {
                        change_goods_number(rec_id, goods_number, price);
                    }
                }
                function change_goods_number(rec_id, goods_number, price) {
                    if (goods_number < 1) {
                        alert("购买数量不能少于1件");
                    }else{
                        var xmlhttp = new XMLHttpRequest();
                        var act = "<?php echo U(GROUP_NAME.'/Cart/updateCart');?>";
                        xmlhttp.open("POST", act, false);
                        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                        xmlhttp.send("goods_id=" + rec_id + "&num=" + goods_number + "&update=1");

                        if (xmlhttp.responseText == true) {
                            $('#goods_number_' + rec_id).val(goods_number);//更新数量
                            $('#goods_subtotal_' + rec_id).html('￥<em name=price_'+rec_id+'>' + price * goods_number + '</em>元');//更新小计
                            jisuan();
                        } else {
                            alert('传输错误，请稍后重试');
                        }
                    }
                }
                function remove(id){
                    var xmlhttp = new XMLHttpRequest();
                    var act = "<?php echo U(GROUP_NAME.'/Cart/updateCart');?>";
                    xmlhttp.open("POST", act, false);
                    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    xmlhttp.send("goods_id=" + id + "&num=0");
                    if (xmlhttp.responseText == true) {
                        $("#tr_goods_"+id).remove();
                    } else {
                        alert('传输错误，请稍后重试');
                    }
                }
                function jisuan(){
                    var total = 0;
                    var box = document.getElementsByName("box");
                    for(var i=0;i<box.length;i++){
                        if(box[i].checked){
                            var price=document.getElementsByName('price_'+box[i].value)[0].innerHTML;
                            total +=parseFloat(price);
                        }
                    }
                    document.getElementsByName('total')[0].innerText = total ;
                }
                function checkout(){
                    var box = document.getElementsByName("box");
                    var value;
                    for(var i=0;i<box.length;i++){
                        if(box[i].checked){
                            value=true;
                            break;
                        }
                    }
                    if(value){

                        var url="<?php echo U(GROUP_NAME.'/Order/addOrder');?>";

                        var body = $(document.body),
                                form = $("<form method='post' ></form>"),
                                input;
                        form.attr({"action":url});
                        for(var i=0;i<box.length;i++){
                            if(box[i].checked){
                                input = $("<input type='hidden'>");
                                input.attr({"name":box[i].value});
                                input.val($('#goods_number_' + box[i].value).val());
                                form.append(input);
                            }
                        }
                        form.appendTo(document.body);
                        form.submit();
                        document.body.removeChild(form[0]);
                    }else {
                        alert('请选择商品');
                    }
                }
            </script>


            <script type="text/javascript" charset="utf-8">
                function fittings_to_flow(goodsId, parentId) {
                    var goods = new Object();
                    var spec_arr = new Array();
                    var number = 1;
                    goods.spec = spec_arr;
                    goods.goods_id = goodsId;
                    goods.number = number;
                    goods.parent = parentId;
                    Ajax.call('flow.php?step=add_to_cart', 'goods=' + $.toJSON(goods), fittings_to_flow_response, 'POST', 'JSON');
                }
                function fittings_to_flow_response(result) {
                    if (result.error > 0) {
                        // 如果需要缺货登记，跳转
                        if (result.error == 2) {
                            if (confirm(result.message)) {
                                location.href = 'user.php?act=add_booking&id=' + result.goods_id;
                            }
                        }
                        else if (result.error == 6) {
                            openSpeDiv(result.message, result.goods_id, result.parent);
                        }
                        else {
                            alert(result.message);
                        }
                    }
                    else {
                        location.href = 'flow.php';
                    }
                }
            </script>
            <div class="blank"></div>
            <div class="block_s">


            </div>


        </DIV>
        <div class="block_s">


        </div>
    </div>
</DIV>


</div>
<div class="blank5"></div>
</body>
<script type="text/javascript">
    var process_request = "正在处理您的请求...";
    var username_empty = "- 用户名不能为空。";
    var username_shorter = "- 用户名长度不能少于 3 个字符。";
    var username_invalid = "- 用户名只能是由字母数字以及下划线组成。";
    var password_empty = "- 登录密码不能为空。";
    var password_shorter = "- 登录密码不能少于 6 个字符。";
    var confirm_password_invalid = "- 两次输入密码不一致";
    var email_empty = "- Email 为空";
    var email_invalid = "- Email 不是合法的地址";
    var agreement = "- 您没有接受协议";
    var msn_invalid = "- msn地址不是一个有效的邮件地址";
    var qq_invalid = "- QQ号码不是一个有效的号码";
    var home_phone_invalid = "- 家庭电话不是一个有效号码";
    var office_phone_invalid = "- 办公电话不是一个有效号码";
    var mobile_phone_invalid = "- 手机号码不是一个有效号码";
    var msg_un_blank = "* 用户名不能为空";
    var msg_un_length = "* 用户名最长不得超过7个汉字";
    var msg_un_format = "* 用户名含有非法字符";
    var msg_un_registered = "* 用户名已经存在,请重新输入";
    var msg_can_rg = "* 可以注册";
    var msg_email_blank = "* 邮件地址不能为空";
    var msg_email_registered = "* 邮箱已存在,请重新输入";
    var msg_email_format = "* 邮件地址不合法";
    var msg_blank = "不能为空";
    var no_select_question = "- 您没有完成密码提示问题的操作";
    var passwd_balnk = "- 密码中不能包含空格";
    var username_exist = "用户名 %s 已经存在";
    var compare_no_goods = "您没有选定任何需要比较的商品或者比较的商品数少于 2 个。";
    var btn_buy = "购买";
    var is_cancel = "取消";
    var select_spe = "请选择商品属性";
</script>
</html>